package com.bruce.pattern.behavioral.chain.demo1;

import java.util.List;

/**
 * Created by bruce on 2018/11/11 17:18
 */
public class Chain<T> {

    private int handlerIndex = 0;

    private List<ChainHandler<T>> handlers;

    public Chain(List<ChainHandler<T>> handlers) {
        this.handlers = handlers;
    }

    public void process(T object){
        if (handlerIndex < handlers.size()){
            handlers.get(handlerIndex++).execute(this, object);
        }
    }


}
